﻿<%@ Page Language="C#" MasterPageFile="~/Views\Home\test.master" Inherits="System.Web.Mvc.ViewPage" %>
 		<asp:Content ContentPlaceHolderID="test" runat="server">
 			<div class="tab_container">

   				 
   				 <!- ---------------------------------------- TAB 2 MANAGE BOOK -------------------------- -->
   				 
   				 <div class="tab_content">
   				 <% TestProject.Book book = ViewData["Book"] as TestProject.Book; %>
   				 	  <% if(Html.Encode(Session["level"]) != "1" && Session["level"] != null){ %>
   				 	  	<div>
   				 	  		<a class="editBook_showForm" href="#">Edit</a>
	                		<a class="deleteBook" id="<%= Html.Encode(book.book_ID) %>" href="#">Delete</a>
   				 	  	</div>
   				 	  	
   				 	  
   				 	  	
   				 	  	<div class="success" id="eb_success">Book Edited!</div>
	   				  	<div class="success" id="db_success">Book Deleted!</div>
	   				  	<div id="form_editBook">
	   				  	<table>
	   				  		<input id="inp_id" type="hidden" disabled="disabled" value="<%= Html.Encode(book.book_ID) %>" />
	   				  		<tr><td style="border:0px; font-size: 16px;">ISBN:</td><td style="border:0px"><input size="40" id="inp_isbn" type="text" value="<%= Html.Encode(book.isbn) %>" /></td></tr>
	   				  		<tr><td style="border:0px; font-size: 16px;">Title:</td><td style="border:0px"><input size="40" id="inp_title" type="text" value="<%= Html.Encode(book.title) %>" /></td></tr>
	   				  		<tr><td style="border:0px; font-size: 16px;">Author:</td><td style="border:0px"><input size="40" id="inp_author" type="text" value="<%= Html.Encode(book.author) %>" /></td></tr>
	   				  		<tr><td style="border:0px; font-size: 16px;">Publisher:</td><td style="border:0px"><input size="40" id="inp_publisher" type="text" value="<%= Html.Encode(book.publisher) %>" /></td></tr>
	   				  	</table>
	   				  		 &nbsp;Genre: <input id="ab_genre" type="hidden" value=""/><br/>
	   				  		
	   				  			<% List<TestProject.Genre> genreList = new List<TestProject.Genre>(0); %>
	   				  			<% genreList = ViewData["Genres"] as List<TestProject.Genre>;  %>
	   				  		
	   				  			<% foreach (TestProject.Genre genre in (ViewData["AllGenres"] as List<TestProject.Genre>)) {%>
	   				  			<div class="inline" style="min-width:150px;">
	   				  				<% TestProject.Genre result = genreList.Find(delegate(TestProject.Genre g){ return g.genre_ID == genre.genre_ID; }); %>
	   				  				<% if(result == null){ %>
	   				  					<input type="checkbox" class="checkbox" name="<%= Html.Encode(genre.genre_ID) %>" value="<%= Html.Encode(genre.type) %>" /><%= Html.Encode(genre.type) %><br/>
	   				  				<% } %>
	   				  				<% else{ %>
	   				  					<input type="checkbox" checked="true" class="checkbox" name="<%= Html.Encode(genre.genre_ID) %>" value="<%= Html.Encode(genre.type) %>" /><%= Html.Encode(genre.type) %><br/>
	   				  				<% } %>
	   				  			
	   				  			</div>
	   				  			<% } %>
	   				  		<br/>&nbsp;Synopsis: <br/>&nbsp;<textarea rows="7" cols="80" id="inp_synopsis"><%= Html.Encode(book.synopsis) %></textarea> <br/>
	   				  		<input type="button" value="Edit" id="editBook"/>&nbsp; <input type="button" value="Cancel" id="cancel_editBook"/>
	   				  	</div>
	                	
	                <%} %>
	                	<div class="error"></div>
   					
   						<h3 style="margin:0px;"><%= Html.Encode(book.title) %></h3>
   						by: <%= Html.Encode(book.author) %><br />
   						<% if(Session["level"] != null){ %>
   						<% if (Html.Encode(ViewData["isReserved"])=="True") { %>You have reserved this book.<% } else { %>
   						<input type="button" id="reserveBook" value="Reserve Book" />
   						<input type="hidden" id="book_id" value = "<%= Html.Encode(book.book_ID) %>" />
   						<input type="hidden" id="user_id" value = "<%= Html.Encode(Session["user_id"]) %>" />
   						<input id="res_isbn" type="hidden" value="<%= Html.Encode(book.isbn) %>" />
   						<% }} %><br /><br />
   						Copies
   						
   						<% if(Session["level"] != null && Html.Encode(Session["level"]) != "1"){ %>
   							<a id="showACForm" href="#"> Add a copy</a>
   							<form id="ac_form">
   								<input  id="ac_ISBN" type="hidden" value="<%= Html.Encode(book.isbn) %>" />
   								<label>Call Number: &nbsp;&nbsp;</label><input id="ac_callNo" type="text" value="" />
   								<button id="addCopy">Save</button>
   							</form>
   							<form id="ec_form">
   								<input  id="ec_copy_id" type="hidden" value="" />
   								<label>Call Number: &nbsp;&nbsp;</label><input id="ec_callNo" type="text" value="" />
   								<button id="editCopy">Save</button>
   							</form>
   							<br />
   						<% } %>   						
	   				  	<table width="100%" cellspacing="0">
	   				  		<thead>
	   				  			<tr>
	   				  				<td width="20%">Copy Number</td>
	   				  				<td width="40%">Status</td>
	   				  				<% if( Html.Encode( Session["level"]) != "1" && Session["level"] != null){ %><td width="20%"></td><% } %>
	   				  				<% if( Html.Encode( Session["level"]) != "1" && Session["level"] != null){ %><td width="20%"></td><% } %>	
	   				  			</tr>
	   				  		</thead>
	   				  		<tbody>
   								<% foreach (TestProject.Copy copy in (ViewData["Copies"] as List<TestProject.Copy>)) {%>
	   				  			<tr class="user_row">
	   				  				<td align="center" id="<%= Html.Encode(copy.copy_ID) %>_inp_call_no"><%= Html.Encode(copy.callNo) %></td>   
	   				  				<td align="center"><% if (Html.Encode(copy.status) == "True") { %>ON LOAN<% if( Html.Encode( Session["level"]) != "1" && Session["level"] != null){ %><br /><%= Html.Encode(copy.borrower) %><% }} else { %>AVAILABLE<% } %></td>
	   				  				<% if( Html.Encode( Session["level"]) != "1" && Session["level"] != null){ %><td align="center">
	   				  					<a href="#" class="showECForm" id="<%= Html.Encode(copy.copy_ID) %>">EDIT</a>	   				  					
	   				  				</td><% } %>	
	   				  				<% if( Html.Encode(copy.status) == "True" && Html.Encode( Session["level"]) != "1" && Session["level"] != null){ %><td align="center">
	   				  					<a href="#" class="return_book" id="<%= Html.Encode(copy.copy_ID) %>">RETURN</a>	   				  					
	   				  				</td><% } %>	
	   				  			</tr>
		   				  		<% } %>
		   				  			
	   				  		</tbody>
	   				  	</table>		   				  	
   						<br />  
		   				Reservations
		   				<div class="success" id="cancel_reservation_success">Reservation successfully cancelled.</div>
		   				<table width="100%" cellspacing="0">
		   					<thead>
		   				  		<td width="40%">User</td>
		   				  		<td width="20%">Date of Reservation</td>
		   				  		<td width="20%">Pickup Date Start</td>
		   				  		<td width="20%">Pickup Date End</td>
		   				  	</thead>   				  		
		   				  	<tbody id="tbl_reservations">
		   				  	<% int numCopies = (int)ViewData["available"]; %>
							<% foreach (TestProject.Reservation item in (ViewData["reservations"] as List<TestProject.Reservation>)) {%>
							<tr id="<%= Html.Encode(item.reservation_ID) %>_row" <% if (numCopies>0 && Html.Encode( Session["level"]) != "1" && Session["level"] != null)  { %>class="reservation_row" <% }  else { %>class="user_reservation_row" <% }%>>
								<td align="center" id="<%= Html.Encode(item.user_ID) %>_user"><%= Html.Encode(item.user) %></td>
								<td align="center" id="<%= Html.Encode(item.reservation_ID) %>_start"><%= Html.Encode(item.reservation_date_str) %></td>
								<td align="center" id="<%= Html.Encode(item.reservation_ID) %>_start"><%= Html.Encode(item.pickupdate_start_str) %></td>
								<td align="center" id="<%= Html.Encode(item.reservation_ID) %>_start"><%= Html.Encode(item.pickupdate_end_str) %></td>
							</tr>
							<% numCopies--; } %>
							</tbody>
					  	</table> 
					  	<font size="2">*Rows in <font color="#32CD32">green</font> mean that corresponding reservations are ready for loan.</font>				
					  	<br /> <br />		
   						<center><img width="300px;" src="http://images.amazon.com/images/P/<%= Html.Encode(book.isbn) %>.01.MZZZZZZZ" /></center><hr /><br />
   						ISBN: <%= Html.Encode(book.isbn) %><br />
   						Publisher: <%= Html.Encode(book.publisher) %><br />						
   						Genres:    						  						
   						<% foreach (TestProject.Genre genre in (ViewData["Genres"] as List<TestProject.Genre>)) {%>	   				  			
	   				  			<div><%= Html.Encode(genre.type) %></div>
	   				  	<% } %>
	   				  	<br />
   						<b>Synopsis:</b><br />
   						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= Html.Encode(book.synopsis) %><br />
   				 </div>
   				 
   				
   				 
   			</div>
 			
 		</asp:Content>
 	
 	
